package com.config.channels.controller;

import com.config.channels.entity.Version;
import com.config.channels.service.VersionService;
import com.config.channels.utils.ResObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

@RestController
public class VersionController {

    @Autowired
    private VersionService versionService;

    @RequestMapping(value = "/api/v1/config")
    public Version getConfig(@RequestParam String version) {

        Version ret = versionService.get(version);

        return ret;
    }

    @RequestMapping(value = "/api/v1/set")
    public ResObject setConfig(@RequestParam String version,@RequestParam String infos) throws UnsupportedEncodingException {

        Version ver = new Version();
        ver.version = version;
        ver.infos = infos;
        versionService.save(ver);
        return new ResObject();
    }

}
